﻿using System;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using MarkdownRow.Assets;

namespace MarkdownRow.Edit.CompletionData;

public class ParagraphCompletion : CompletionData
{
    public ParagraphCompletion(DocItem item) : base(item)
    {
        var url = new Uri("avares://MarkdownRow/Assets/Image/pa.png");
        Image = new Bitmap(AssetLoader.Open(url));
    }

    public override void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
    {
        textArea.Document.Remove(completionSegment.Offset-1,1);
        textArea.Document.Replace(completionSegment,Text+" ");
    }
}